package com.lottery.im.module.result.presenter;

import android.app.Activity;
import com.lottery.im.MyApplication;
import com.lottery.im.api.ApiClient;
import com.lottery.im.api.observer.ShowTipListObserver;
import com.lottery.im.api.observer.ShowTipObserver;
import com.lottery.im.api.result.entity.good.GoodList;
import com.lottery.im.api.result.entity.good.SetterByGameType;
import com.lottery.im.base.BaseFragmentPresenter;
import com.lottery.im.module.result.view.GetListView;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 作者：cyy
 * 时间：2018/10/8。
 */
public class GetListPresenter extends BaseFragmentPresenter<GetListView> {

  public GetListPresenter(Activity activity,
      GetListView iView,
      LifecycleProvider<FragmentEvent> provider) {
    super(activity, iView, provider);
  }

  String token = MyApplication.getInstance().getToken();
  String userId = MyApplication.getInstance().getUserInfo().getUserId();

  public void getSetterId(String gameType){
    ApiClient.getApiRetrofitInstance()
        .querySetterByGameType(gameType,userId,token)
        .throttleFirst(2,TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new ShowTipObserver<SetterByGameType>(activity) {
          @Override public void onSuccess(SetterByGameType setterByGameType) {
            iView.querySetterByGameTypeResult(setterByGameType.getGameTypeSetterList());
          }
        });
  }

  public void getListResult(int setterId){
    ApiClient.getApiRetrofitInstance()
        .queryGoodList(setterId,userId,token)
        .throttleFirst(2,TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new ShowTipListObserver<GoodList>(activity) {
          @Override public void onSuccess(List<GoodList> t) {
            iView.getListSuccess(t);
          }
        });
  }
}
